package com.example.hangzhou.welbeing.mytestdemoapp.animation.animationActivity;

import android.animation.Animator;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.transition.Explode;
import android.transition.Transition;
import android.transition.TransitionManager;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.widget.ImageView;

import com.example.hangzhou.welbeing.mytestdemoapp.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 杭州惟君医疗科技有限公司17
 * Created by 20433 on 2018/5/8
 *
 * @desc 东风山河绿，春已不折柳，繁花看不尽，处处惹人留
 * @desc 佛祖镇楼，bug辟容易
 */

public class AnimatedTransitionsFourthActivity extends AppCompatActivity {
    @Bind(R.id.activity_animation_transitions_fourth_toolbar)
    Toolbar activityAnimationTransitionsFourthToolbar;
    @Bind(R.id.activity_animation_transitions_fourth_imageview)
    ImageView activityAnimationTransitionsFourthImageview;
    @Bind(R.id.app_bar)
    AppBarLayout appBar;
    @Bind(R.id.activity_animation_transitions_fourth_fab_01)
    FloatingActionButton activityAnimationTransitionsFourthFab01;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation_transitions_fourth);
        ButterKnife.bind(this);
//        TransitionSet cotentTransition = new TransitionSet();
//        Slide slide = new Slide(Gravity.BOTTOM);
//        slide.setDuration(500);
//        slide.excludeTarget(android.R.id.navigationBarBackground, true);
//        slide.excludeTarget(android.R.id.statusBarBackground, true);
//        slide.excludeTarget(R.id.activity_animation_transitions_fourth_toolbar, true);
//        slide.excludeTarget(R.id.activity_animation_transitions_fourth_fab_01, true);
//        cotentTransition.addTransition(slide); //fab进入动画
//        FABTransition fabTransition = new FABTransition(activityAnimationTransitionsFourthFab01, this);
//        fabTransition.addTarget(R.id.fab);
//        fabTransition.setDuration(500);
//        cotentTransition.addTransition(fabTransition);
//        getWindow().setEnterTransition(cotentTransition);

        Rect viewRect = new Rect();
        appBar.getGlobalVisibleRect(viewRect);
        Explode explode = new Explode();
        explode.setEpicenterCallback(new Transition.EpicenterCallback() {
            @Override
            public Rect onGetEpicenter(Transition transition) {
                return viewRect;
            }
        });
        explode.setDuration(1000);
        TransitionManager.beginDelayedTransition(appBar, explode);

       // doCircle(activityAnimationTransitionsFourthImageview);
    }
    private void doCircle(View myView) {

        int cx = myView.getWidth() / 2;
        int cy = myView.getHeight() / 2;

        int finalRadius = Math.max(myView.getWidth(), myView.getHeight());


        Animator animation = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
        animation.setDuration(2000);
        myView.setVisibility(View.VISIBLE);
        animation.start();
    }
}
